Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Use non-SeqCst in module example of atomics #119138

Conversation

AngelicosPhosphoros
Copy link
Contributor

I done this for this reasons:

  1. The example now shows that there is more Orderings than just SeqCst.
  2. People who would copy from example would now have more suitable orderings for the job.
  3. SeqCst is both much harder to reason about and not needed in most situations.

IMHO, we should encourage people to think and use memory orderings that is suitable to task instead of blindly defaulting to SeqCst.

r? @m-ou-se

I done this for this reasons:
1. The example now shows that there is more Orderings than just SeqCst.
2. People who would copy from example would now have more suitable orderings for the job.
3. SeqCst is both much harder to reason about and not needed in most situations.

IMHO, we should encourage people to think and use memory orderings that is suitable to task instead of blindly defaulting to SeqCst.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 19, 2023
@@ -138,7 +138,7 @@
//!
//! In general, *all* atomic accesses on read-only memory are Undefined Behavior. For instance, attempting
//! to do a `compare_exchange` that will definitely fail (making it conceptually a read-only
//! operation) can still cause a page fault if the underlying memory page is mapped read-only. Since
//! operation) can still cause a segmentation fault if the underlying memory page is mapped read-only. Since
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, page faults are about valid memory that is not mapped to physical pages and absolutely legal (but slow) while text describes illegal memory access which is called segmentation fault. I am not an expert though and may be not correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think page fault is the more precise term here it's more lower level. The OS will then either do something useful with the page fault and continue normally, or it will crash the process with a SIGSEGV if it did something bad (which would be the case here) (I'm not entirely sure whether this is accurate but I think it is?). I'm not sure what the best way to describe this is here, it seems fine to change it to segmentation fault, that is probably more useful to users.

@AngelicosPhosphoros
Copy link
Contributor Author

r? libs

@rustbot rustbot assigned joshtriplett and unassigned m-ou-se Dec 29, 2023
@AngelicosPhosphoros
Copy link
Contributor Author

r? libs

@rustbot rustbot assigned thomcc and unassigned joshtriplett Jan 13, 2024
Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks. Using the "canonical" lock ordering when implementing a lock definitely makes sense and also helps further the point of using correct orderings instead of just throwing SeqCst at it and hoping that the algorithm is correct.

@Noratrieb
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 18, 2024

📌 Commit 1c5b2ce has been approved by Nilstrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 18, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 19, 2024
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#118665 (Consolidate all associated items on the NonZero integer types into a single impl block per type)
 - rust-lang#118798 (Use AtomicU8 instead of AtomicUsize in backtrace.rs)
 - rust-lang#119062 (Deny braced macro invocations in let-else)
 - rust-lang#119138 (Docs: Use non-SeqCst in module example of atomics)
 - rust-lang#119907 (Update `fn()` trait implementation docs)
 - rust-lang#120083 (Warn when not having a profiler runtime means that coverage tests won't be run/blessed)
 - rust-lang#120107 (dead_code treats #[repr(transparent)] the same as #[repr(C)])
 - rust-lang#120110 (Update documentation for Vec::into_boxed_slice to be more clear about excess capacity)
 - rust-lang#120113 (Remove myself from review rotation)
 - rust-lang#120118 (Fix typo in documentation in base.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 19, 2024
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#118665 (Consolidate all associated items on the NonZero integer types into a single impl block per type)
 - rust-lang#118798 (Use AtomicU8 instead of AtomicUsize in backtrace.rs)
 - rust-lang#119062 (Deny braced macro invocations in let-else)
 - rust-lang#119138 (Docs: Use non-SeqCst in module example of atomics)
 - rust-lang#119907 (Update `fn()` trait implementation docs)
 - rust-lang#120083 (Warn when not having a profiler runtime means that coverage tests won't be run/blessed)
 - rust-lang#120107 (dead_code treats #[repr(transparent)] the same as #[repr(C)])
 - rust-lang#120110 (Update documentation for Vec::into_boxed_slice to be more clear about excess capacity)
 - rust-lang#120113 (Remove myself from review rotation)
 - rust-lang#120118 (Fix typo in documentation in base.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f9076bb into rust-lang:master Jan 19, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 19, 2024
Rollup merge of rust-lang#119138 - AngelicosPhosphoros:use_proper_atomics_in_spinlock_example, r=Nilstrieb

Docs: Use non-SeqCst in module example of atomics

I done this for this reasons:
1. The example now shows that there is more Orderings than just SeqCst.
2. People who would copy from example would now have more suitable orderings for the job.
3. SeqCst is both much harder to reason about and not needed in most situations.

IMHO, we should encourage people to think and use memory orderings that is suitable to task instead of blindly defaulting to SeqCst.

r? `@m-ou-se`
@AngelicosPhosphoros AngelicosPhosphoros deleted the use_proper_atomics_in_spinlock_example branch January 19, 2024 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants